-- -----------------------------------------------------------------------------
-- | WonderTek [ 网络无处不在，沟通及时到达 ]
-- -----------------------------------------------------------------------------
-- | Copyright (c) 2012, WonderTek, Inc. All Rights Reserved.
-- -----------------------------------------------------------------------------
-- | Author: xxxx <xxxx@xxxx.com>
-- -----------------------------------------------------------------------------
-- | Desc: 常用功能函数
-- -----------------------------------------------------------------------------

function backBtn(sprite)
    Scene:back()
end

function goHome(sprite)
    Scene:go(Alias.home)
end

function goMail(sprite)
    Scene:setReturn(Scene:getNameByHandle(Sprite:getCurScene()), Alias.mailList)
    Scene:go(Alias.mailList)
end

function goDangZhen(sprite)
    Scene:setReturn(Scene:getNameByHandle(Sprite:getCurScene()), Alias.dangzhengxinxiList)
    Scene:go(Alias.dangzhengxinxiList)
end

function goGongWen(sprite)
    Scene:setReturn(Scene:getNameByHandle(Sprite:getCurScene()), Alias.gongwen)
    Scene:go(Alias.gongwen)
end

function setAllShoworHide(sprite, isShow)
    Sprite:setVisible(sprite, isShow)
    Sprite:setActive(sprite, isShow)
    Sprite:setEnable(sprite, isShow)
end
 -- 获得服务器地址
function getUrl()
    return Config:get('server_url')
end

function getGongwenUrl(cmd, searchStr, pageindex, pagesize)
    local url = Config:get('server_url') .. 'Document/DocumentManager.ashx?cmd=' .. cmd .. '&usercode=' .. Config:get('username')
    if cmd == 'yibanlist' or cmd == 'yiyuelist' then
        return url .. '&orgid=' .. Config:get('orgId') .. '&pageindex='..(pageindex or '')..'&pagesize='..(pagesize or '')..'&searchValue=' .. (searchStr or '')
    end
    return url
end
function getJsonArrayCount(data)
    local count = 0
    if data then
        if  #data == 0 and type(data[0]) == 'table' then
            count = 1
        else
            count = #data + 1
        end
    else
    return 0
    end
    return count
end
function getMailUrl(oper)
    local mailServer = Config:get('mailServer')
    local mailUser = Config:get('mailuser')
    local mailpwd = Config:get('mailpwd')
    local ip = 'http://120.209.131.145/webcloud/'
    local param = 'mailServer=' .. mailServer .. '&mailUser=' .. mailUser .. '&mailPassword=' .. mailpwd
    if oper == 'detail' then
        return ip .. 'parser/base/getMailDetail.html?' .. param
    elseif oper == 'send' then
        return ip .. 'parser/base/sendMail.html?' .. param
    elseif oper == 'upload' then
        return ip .. 'upload/UGC_GetUploadUrl.html?'
    else
        return ip .. 'parser/base/getMailList.html?' .. param
    end
end

function getFileNameAndExt(filePath)
    local reversStr = string.reverse(filePath)
    local line = string.find(reversStr, '%/')
    local point = string.find(reversStr, '%.')
    if point and point ~= 1 then
        local fileName
        if line then
            fileName = string.sub(filePath, -line+1, -point-1)
        else
            fileName = string.sub(filePath, 1, -point-1)
        end
        local fileExt = string.sub(filePath, -point+1)
        return fileName, fileExt
    end
    return nil
end

function handleF2Key(sprite)
    if Loading:isShow() then
        Loading:close()
        return
    elseif Dialog:isShow() then
        Dialog:close()
        return
    end
    backBtn()
end

function setSpriteVisible(sprite, visible)
    Sprite:setVisible(sprite, visible)
    Sprite:setEnable(sprite, visible)
end

function doExit()
    IO:dirRemove('WONDER:\\temp', 1)
    Scene:exit()
end
